import 'package:flutter/material.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';

import '../../utils/screenutil/fit.dart';

enum SpinKitType {
  CubeGrid,
  FadingCircle,
  DoubleBounce,
}

class SVGLoading extends StatelessWidget {
  SpinKitType type;
  String tips;
  Color iconColor;
  double size;
  Color fontsColor;

  SVGLoading(
      {SpinKitType type = SpinKitType.FadingCircle,
      String tips = '小主请稍等片刻',
      Color iconColor = const Color.fromRGBO(58, 98, 237, .9),
      double size = 40,
      Color fontsColor = Colors.black26})
      : this.tips = tips,
        this.type = type,
        this.iconColor = iconColor,
        this.size = size,
        this.fontsColor = fontsColor;

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 640.f,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          createSpink(type, iconColor, size),
          SizedBox(height: 10),
          Text(
            "$tips",
            style: TextStyle(
              color: fontsColor,
              fontSize: 14,
              fontFamily: 'RubikMonoOne',
              fontWeight: FontWeight.normal,
              fontStyle: FontStyle.italic,
            ),
          ),
        ],
      ),
    );
  }

  /// 创建Spink
  /// * [type] SpinKitType|动画类型|详见：SpinKitType
  Widget createSpink(SpinKitType type, Color iconColor, double size) {
    switch (type) {
      case SpinKitType.CubeGrid:
        return SpinKitCubeGrid(
          color: iconColor,
          size: size,
        );
      case SpinKitType.DoubleBounce:
        return SpinKitDoubleBounce(
          color: iconColor,
          size: size,
        );
      case SpinKitType.FadingCircle:
        return SpinKitFadingCircle(
          color: iconColor,
          size: size,
        );
    }
  }
}
